package com.tencent.wxcloudrun.controller;

import com.tencent.wxcloudrun.model.Goods;
import com.tencent.wxcloudrun.response.R;
import com.tencent.wxcloudrun.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: GoodsController
 * Package: com.tencent.wxcloudrun.controller
 * Description:
 *
 * @Date: 2023/1/22 8:34 AM
 * @Author: wht
 */
@Slf4j
@RestController
//@RestController = @Controller + @ResponseBody
@RequestMapping("/admin")
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    @PutMapping("/addOneGoods")
    public <T> R<T> addOneGoods(@RequestBody Goods goods) {
        goodsService.addOneGoods(goods);
        return R.successMsg("添加成功！");
    }

    @PatchMapping("/updateOneGoodsById")
    public <T> R<T> updateOneGoodsById(@RequestBody Goods goods) {
        goodsService.updateOneGoodsById(goods);
        return R.successMsg("修改成功！");
    }

    @PostMapping("/getGoodsList")
    public <T> R<T> getGoodsList(@RequestBody Goods goods) {
        List<Goods> goods_list = goodsService.getGoodsList(goods);
        return R.successData(goods_list);
    }

//    @GetMapping("/getOneGoodsById/{id}")
//    public <T> R<T> getOneGoodsById(@PathVariable("id") Integer id) {
//        Goods goods = goodsService.getOneGoodsById(id);
//        return R.successData(goods);
//    }

}
